package com.mapper;

import com.domain.Blog;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Mapper
public interface BlogMapper {
    //分页所有blog数据
    public List<Blog> findAllBlog();
    //热门帖子展示（访问量前五）
    @Select("select * from t_blog where t_blog.delete = 0 order by pageview desc limit 0 , 5")
    public List<Blog> findHotBlog();
    //分类分页查找blog
    public List<Blog> findBlogByType(int checkType);
    //关键字分页查找blog
    public List<Blog> findBlogByKeyWords(String keyWords);
    //根据id查找Blog
    @Select("select * from t_blog where id = #{id}")
    public Blog findBlogById(Integer id);
    //每查找一次blog,访问量+1
    @Update("update t_blog set pageview = pageview + 1 where id = #{id}")
    public void addPageView(Integer id);
    //根据title查找Blog
    public List<Blog> findBlogByTitle(String keyWords);
    //删除blog（修改delete状态）
    @Update("update t_blog set t_blog.delete = 1 where id = #{id}")
    public int deleteblog(Integer id);
    //发布blog
    public int insertBlog(Blog blog);
    //更新blog
    public int updateBlog(Blog blog);
    //写入关联信息到t_b_t表
    @Insert("insert into t_b_t(bid,tid) values(#{bid},#{tid})")
    public int insertTBT(Map map);
    //删除关联关系
    @Delete("delete * from t_b_t where bid = #{bid}")
    public int deleteTBT(int bid);



    //判断关联关系是否存在
//    @Select("select count(*) from t_b_t where bid = #{bid} and tid = #{tid}")
//    int isExist(Map map);
}
